package LinkedList;
//找到相交链表的相交节点，若没有相交则返回null
public class Solution8 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode plong = headA;
        ListNode pshort = headB;
        int len1 = 0;
        int len2 = 0;
        while(plong!=null){
            len1++;
            plong = plong.next;
        }
        while(pshort!=null){
            len2++;
            pshort = pshort.next;
        }
        plong = headA;
        pshort = headB;
        int len = len1-len2;
        if(len<0){
            plong = headB;
            pshort = headA;
            len = len2-len1;
        }
        while(len!=0){
            plong = plong.next;
            len--;
        }
        while(plong!=pshort){
            plong = plong.next;
            pshort = pshort.next;
        }
        return plong;
    }
}
